package com.tjsinfo.tjsoa.worklog.action;

import java.util.Date;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tjsinfo.tjsoa.system.bo.ISystemUserBo;
import com.tjsinfo.tjsoa.system.vo.TSystemUser;
import com.tjsinfo.tjsoa.system.vo.User;
import com.tjsinfo.tjsoa.worklog.bo.IWorkLogMainBo;
import com.tjsinfo.tjsoa.worklog.vo.WorkLogMain;
/**
 * 工作日志日历
 * @author wangxiaowei
 *
 */
public class WorkLogDateModleAction extends Action{
	private IWorkLogMainBo workLogMainBo;
	private ISystemUserBo systemUserBo;
	
	public ISystemUserBo getSystemUserBo() {
		return systemUserBo;
	}

	public void setSystemUserBo(ISystemUserBo systemUserBo) {
		this.systemUserBo = systemUserBo;
	}

	public IWorkLogMainBo getWorkLogMainBo() {
		return workLogMainBo;
	}

	public void setWorkLogMainBo(IWorkLogMainBo workLogMainBo) {
		this.workLogMainBo = workLogMainBo;
	}

	/* (non-Javadoc)
	 * @see org.apache.struts.action.Action#execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 */
	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		// TODO Auto-generated method stub
		Date date = new Date();
		User user = getUser(request);
		
		Map<Date, WorkLogMain> worklogmap = getMap(date, user);
		request.setAttribute("worklogmap", worklogmap);
		request.setAttribute("yueli", date);
		return findforward(mapping);
	}

	protected ActionForward findforward(ActionMapping mapping) {
		return mapping.findForward("ok");
	}

	protected Map<Date, WorkLogMain> getMap(Date date, User user) {
		Map<Date, WorkLogMain> worklogmap =   workLogMainBo.selectWorkLogTypeAndYearMAP("D", 1900+date.getYear(),user.getUser_id());
		return worklogmap;
	}

	protected User getUser(HttpServletRequest request) {
		HttpSession session = request.getSession();
		User user = (User) session.getAttribute("user");
		return user;
	}
	protected TSystemUser getDefinalutTjsuser(HttpServletRequest request, User user) {
		TSystemUser  tjsuser= systemUserBo.findByIdSystemUser(Integer.parseInt(request.getParameter("id")));
		user.setUser_id(Integer.parseInt(request.getParameter("id")));
		return tjsuser;
	}
}
